--- layout: documentation title: Malloy Documentation footer: /generated/footers/visualizations/segment_maps.html ---

Segment Maps

The plugin currently supports US maps. Segement maps take as input 4 columns: start latitude , start longitude, end latitude, and end longitude of the segment. The model and data styles for the subsequent examples are:

explore: airports is table('malloy-data.faa.airports') {
  primary_key: code
  dimension: name is concat(code, ' - ', full_name)
  measure: airport_count is count()
}

explore: flights is table('malloy-data.faa.flights') {
  primary_key: id2
  rename: origin_code is origin
  rename: destination_code is destination

  join_one: origin is airports with origin_code
  join_one: destination is airports with destination_code

  measure: flight_count is count()

  query: routes_map is {
    group_by: [
      origin.latitude
      origin.longitude
      latitude2 is destination.latitude
      longitude2 is destination.longitude
    ]
    aggregate: flight_count
  }
}

and data styles are

{
  "routes_map": {
    "renderer": "segment_map"
  }
}

Run as a simple query

Departing from Chicago

-- Bug: as a main query we only return 50 results, nested we get the whole thing...
-- query: flights{ where: dep_time = @2003-02 and origin.code ='ORD'}->routes_map
query: flights{ where: dep_time = @2003-02 and origin.code ='ORD'}->{nest:routes_map}
routes_​map
2004006008001,000flight_count

Run as a trellis

By calling the configured map as a nested query, a trellis is formed.

query: flights{ where: dep_time = @2003-02 and origin.code ='ORD'}->{
  group_by: carrier
  aggregate: flight_count
  nest:routes_map
}
carrier flight_​count routes_​map
UA 9,443 100200300400flight_count
AA 7,255 100200300400flight_count
MQ 4,975 50100150200flight_count
DH 3,906 50100150flight_count
NW 702 150200250300350flight_count

Run as a trellis, repeated with different filters

--! {"isRunnable": true, "runMode": "auto", "source": "/inline/e.malloy", "size": "medium", "dataStyles":{"routes_map": {"renderer": "segment_map"}}}
query: flights->{
  group_by: carrier
  aggregate: flight_count
  nest: [
    ord_segment_map is routes_map {where: origin.code: 'ORD'}
    sfo_segment_map is routes_map {where: origin.code: 'SFO'}
    jfk_segment_map is routes_map {where: origin.code: 'JFK'}
  ]
}
carrier flight_​count ord_​segment_​map sfo_​segment_​map jfk_​segment_​map
WN 5,775,777 NaNflight_count 2,5003,0003,500flight_count NaNflight_count
DL 4,477,929 5,00010,00015,00020,000flight_count 2914,262flight_count 2,0004,0006,0008,000flight_count
AA 4,434,727 10,00020,00030,00040,000flight_count 5,00010,00015,00020,000flight_count 5,00010,00015,00020,000flight_count
UA 3,654,646 10,00020,00030,000flight_count 10,00020,00030,00040,000flight_count 114,472flight_count
US 3,205,810 92914,576flight_count 2,0004,0006,0008,000flight_count NaNflight_count